﻿using System;
using System.Collections.Generic;
using System.Text;
using IAnalyze;
using System.Drawing;

namespace IScript
{

    public class EventArgsAnalyzeBegin : EventArgs
    {
        public readonly long GroupID;//报警帧组ID

        public EventArgsAnalyzeBegin()
        {
            GroupID = DateTime.Now.Ticks;
        }
    }

    public class EventArgsAnalyzeAlarm : EventArgs
    {
        public readonly long GroupID;       //报警帧组ID
        public readonly int FrameCount;     //每组报警帧数
        public readonly int FrameIndex;     //报警帧组中序号
        public readonly Bitmap AlarmFrame;  //报警帧
        public readonly DateTime AlarmTime; //报警时间
        //报警区域组
        public readonly Rectangle[] AlarmRegion;
        //报警区域类型组
        public readonly AlarmRegionEnum[] AlarmRegionType;

        /// <summary>
        /// 识别报警事件参数
        /// </summary>
        /// <param name="groupID">报警帧组ID</param>
        /// <param name="frameCount">每组报警帧数</param>
        /// <param name="frameIndex">报警帧组中序号</param>
        /// <param name="alarmFrame">报警帧</param>
        /// <param name="alarmTime">报警时间</param>
        /// <param name="alarmRegion">报警区域组</param>
        /// <param name="alarmRegionType">报警区域类型组</param>
        public EventArgsAnalyzeAlarm(long groupID, int frameCount, int frameIndex, Bitmap alarmFrame, DateTime alarmTime, Rectangle[] alarmRegion, AlarmRegionEnum[] alarmRegionType)
            : base()
        {
            this.GroupID = groupID;
            this.FrameCount = frameCount;
            this.FrameIndex = frameIndex;
            this.AlarmFrame = alarmFrame;
            this.AlarmTime = alarmTime;
            this.AlarmRegion = alarmRegion;
            this.AlarmRegionType = alarmRegionType;
        }
    }

    public class EventArgsAnalyzeEnd : EventArgs
    {
        public readonly long GroupID;//报警帧组ID

        public EventArgsAnalyzeEnd(int groupID)
        {
            this.GroupID = groupID;
        }
    }

    public interface IAnalyzeStrategy
    {
        /// <summary>
        /// 开始识别事件
        /// </summary>
        event EventHandler<EventArgsAnalyzeBegin> AnalyzeBegin;
        /// <summary>
        /// 识别报警事件
        /// </summary>
        event EventHandler<EventArgsAnalyzeAlarm> AnalyzeAlarm;
        /// <summary>
        /// 识别结束事件
        /// </summary>
        event EventHandler<EventArgsAnalyzeEnd> AnalyzeEnd;

        /// <summary>
        /// 两个识别帧之间跳过的帧数
        /// </summary>
        int FrameSkipRate { get; }

        /// <summary>
        /// 对一组视频连续的帧除去跳过的帧之后还剩下的帧数
        /// </summary>
        int FrameAnalyzeCount { get; }

        /// <summary>
        /// 报警阈值
        ///     对一组视频帧进行识别
        ///     报警帧数达到阈值前将报警帧进行缓存
        ///     当报警帧数达到此阈值时
        ///         先将缓存报警帧抛出
        ///         再清空缓存
        ///         接下来的报警帧直接抛出，直到该组识别完毕
        ///     如一组视频帧识别完毕也未达到阈值
        ///         清空缓存
        /// </summary>
        int FrameAlarmThreshold { get; }

        IAnalyze.IAnalyze[] Analyze { set; }

        /// <summary>
        /// 帧宽
        /// </summary>
        int Width { get; set; }

        /// <summary>
        /// 帧高
        /// </summary>
        int Height { get; set; }


        /// <summary>
        /// 输入视频流
        /// </summary>
        /// <param name="stream">视频流</param>
        /// <param name="width">视频宽度</param>
        /// <param name="height">视频调度</param>
        void InputVideoStream(IntPtr stream);

    }
}
